package com.heu.blood.autologous.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.heu.blood.autologous.service.BloodInformationAutologousService;
import com.heu.blood.autologous.vo.BloodSendAutologousVo;
import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.send.entity.BloodSendEntity;
import com.heu.blood.send.vo.BloodSendVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.heu.blood.autologous.entity.BloodSendAutologousEntity;
import com.heu.blood.autologous.service.BloodSendAutologousService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;



/**
 * 
 *
 * @author lyj
 * @email lyj@heu.com
 * @date 2024-11-30 19:22:05
 */
@RestController
@RequestMapping("autologous/bloodsendautologous")
public class BloodSendAutologousController {
    @Autowired
    private BloodSendAutologousService bloodSendAutologousService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "自体血模块", operate = "分页查询发血表信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodSendAutologousService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ControllerLogAnnotation(module = "自体血模块", operate = "根据id查询本条详细信息")
    public R info(@PathVariable("id") Long id){
		BloodSendAutologousEntity bloodSendAutologous = bloodSendAutologousService.getById(id);

        return R.ok().put("bloodSendAutologous", bloodSendAutologous);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ControllerLogAnnotation(module = "自体血模块", operate = "保存发血表信息")
    public R save(@RequestBody BloodSendAutologousEntity bloodSendAutologous){
		bloodSendAutologousService.save(bloodSendAutologous);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "自体血模块", operate = "修改发血表信息")
    public R update(@RequestBody BloodSendAutologousEntity bloodSendAutologous){
		bloodSendAutologousService.updateById(bloodSendAutologous);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "自体血模块", operate = "批量逻辑删除发血表信息")
    public R delete(@RequestBody Long[] ids){
		bloodSendAutologousService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @RequestMapping("sendBloodAutologous")
    @ControllerLogAnnotation(module = "自体血模块", operate = "发出自体血血液")
    public R sendBloodAutologous(@RequestBody BloodSendAutologousEntity bloodSendAutologous){
        int result=bloodSendAutologousService.sendBloodAutologous(bloodSendAutologous);
        if (result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }

    @RequestMapping("/selectSendBloodAutologousWithId")
    @ControllerLogAnnotation(module = "自体血模块", operate = "根据自体血申请单中申请项id来查询所有发血信息")
    public R selectSendBloodAutologousWithId(@RequestBody BloodSendAutologousEntity bloodSendAutologous){
        List<BloodSendAutologousVo> res = bloodSendAutologousService.selectSendBloodWithId(bloodSendAutologous);
        return R.ok().put("data",res);
    }

    @RequestMapping("/sureGetAutologousBlood")
    @ControllerLogAnnotation(module = "自体血模块", operate = "完成取血，同步更新血液状态，申请单状态、签收库存表以及发血表中信并新增出库表信息")
    public R sureGetAutologousBlood(@RequestBody BloodSendAutologousVo bloodSendAutologousVo){
        int flag = bloodSendAutologousService.sureGetAutologousBlood(bloodSendAutologousVo);
        return R.ok();
    }


}
